flowbox: Add a private api to disable move-cursor
authorMatthias Clasen <mclasen@redhat.com>
Tue, 14 Apr 2020 19:03:57 +0000 (15:03 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 14 Apr 2020 19:07:47 +0000 (15:07 -0400)
Without this, it seems impossible to make cross-section
keynav in the Emoji chooser work. I've tried, but got
lost between the focus, grab_focus, move_cursor and
keynav-failed vfuncs and signals, and their competing
implementations GtkFlowBox and GtkEmojiChooser.

gtk/gtkemojichooser.c
gtk/gtkflowbox.c
gtk/gtkflowboxprivate.h [new file with mode: 0644]

index 57c92cb7356ab4744ae288ff16d3af2b4cee0aaa..e17cabeca2f1571192a65d804215aa0ddd554707 100644 (file)
@@ -766,6 +766,8 @@ stop_search (GtkEntry *entry,
   gtk_popover_popdown (GTK_POPOVER (data));
 }
 
+extern void gtk_flow_box_disable_move_cursor (GtkFlowBox *box);
+
 static void
 setup_section (GtkEmojiChooser *chooser,
                EmojiSection   *section,
@@ -781,6 +783,7 @@ setup_section (GtkEmojiChooser *chooser,
   adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled_window));
 
   gtk_container_set_focus_vadjustment (GTK_CONTAINER (section->box), adj);
+  gtk_flow_box_disable_move_cursor (GTK_FLOW_BOX (section->box));
   gtk_flow_box_set_filter_func (GTK_FLOW_BOX (section->box), filter_func, section, NULL);
   g_signal_connect_swapped (section->button, "clicked", G_CALLBACK (scroll_to_section), section);
 }
index da379f3a8a5de713328cb1864859411aea6bfb55..84ba41df2f9f5019c3efa8eb0566b9624d36ab42 100644 (file)
@@ -76,6 +76,7 @@
 #include <config.h>
 
 #include "gtkflowbox.h"
+#include "gtkflowboxprivate.h"
 
 #include "gtkadjustment.h"
 #include "gtkcontainerprivate.h"
@@ -640,6 +641,8 @@ struct _GtkFlowBoxPrivate {
   GtkFlowBoxCreateWidgetFunc  create_widget_func;
   gpointer                    create_widget_func_data;
   GDestroyNotify              create_widget_func_data_destroy;
+
+  gboolean           disable_move_cursor;
 };
 
 #define BOX_PRIV(box) ((GtkFlowBoxPrivate*)gtk_flow_box_get_instance_private ((GtkFlowBox*)(box)))
@@ -3005,6 +3008,14 @@ gtk_flow_box_toggle_cursor_child (GtkFlowBox *box)
     gtk_flow_box_select_and_activate (box, priv->cursor_child);
 }
 
+void
+gtk_flow_box_disable_move_cursor (GtkFlowBox *box)
+{
+  GtkFlowBoxPrivate *priv = BOX_PRIV (box);
+  
+  priv->disable_move_cursor = TRUE;
+}
+
 static gboolean
 gtk_flow_box_move_cursor (GtkFlowBox      *box,
                           GtkMovementStep  step,
@@ -3023,6 +3034,9 @@ gtk_flow_box_move_cursor (GtkFlowBox      *box,
   GtkAdjustment *adjustment;
   gboolean vertical;
 
+  if (priv->disable_move_cursor)
+    return FALSE;
+
   vertical = priv->orientation == GTK_ORIENTATION_VERTICAL;
 
   if (vertical)
diff --git a/gtk/gtkflowboxprivate.h b/gtk/gtkflowboxprivate.h
new file mode 100644 (file)
index 0000000..c609da3
--- /dev/null
@@ -0,0 +1,26 @@
+/* GTK - The GIMP Toolkit
+ *
+ * Copyright (C) 2020 Red Hat, Inc
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GTK_FLOW_BOX_PRIVATE_H__
+#define __GTK_FLOW_BOX_PRIVATE_H__
+
+#include "gtkflowbox.h"
+
+void gtk_flow_box_disable_move_cursor (GtkFlowBox *box);
+
+#endif